package experiment7;

public class No_1 implements Cloneable{
    public static void main(String[] args) {
        Course1 course1 = new Course1("DS");
        course1.addStudent("student1");
        course1.addStudent("student2");
        course1.addStudent("student3");

        Course1 course2 = (Course1) course1.clone();
        course2.addStudent("student4");
        course2.addStudent("student5");
        course2.addStudent("student6");

        System.out.println(course1.getNumberOfStudents());
        System.out.println(course2.getNumberOfStudents());
    }
}

class Course1 implements Cloneable {
    private String courseName;
    private String[] students = new String[100];
    private int numberOfStudents;

    public Course1(String courseName) {
        this.courseName = courseName;
    }

    public void addStudent(String student) {
        students[numberOfStudents] = student;
        numberOfStudents++;
    }

    public String[] getStudents() {
        return students;
    }

    public int getNumberOfStudents() {
        return numberOfStudents;
    }

    public String getCourse1Name() {
        return courseName;
    }

    public void dropStudent(String student) {
        // Left as an exercise in Exercise 10.9
    }

    public Object clone() {
        try {
            Course1 c = (Course1) super.clone();
            c.students = new String[100];
            System.arraycopy(students, 0, c.students, 0, 100);
            c.numberOfStudents = numberOfStudents;
            return c;
        } catch (CloneNotSupportedException ex) {
            return null;
        }
    }
}